package com.lill.system.web;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.lill.common.component.util.PageUtils;
import com.lill.common.component.util.Query;
import com.lill.common.component.util.R;
import com.lill.support.annotation.CurrentUser;
import com.lill.system.model.SysDictEntity;
import com.lill.system.model.SysUserEntity;
import com.lill.system.service.ISysDictService;

/**
 * 系统数据字典Controller
 *
 * @author lill
 */
@RestController
@RequestMapping("/sys/dict")
public class SysDictController {
    @Autowired
    private ISysDictService dictService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("sys:dict:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<SysDictEntity> dictList = dictService.queryList(query);
        int total = dictService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(dictList, total, query.getLimit(), query.getPage());
        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("sys:dict:info")
    public R info(@PathVariable("id") String id) {
        SysDictEntity dict = dictService.queryObject(id);
        return R.ok().put("dict", dict);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("sys:dict:save")
    public R save(@RequestBody SysDictEntity dict, @CurrentUser SysUserEntity user) {
        dictService.save(dict, user);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("sys:dict:update")
    public R update(@RequestBody SysDictEntity dict) {
        dictService.update(dict);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("sys:dict:delete")
    public R delete(@RequestBody String[] ids) {
        dictService.deleteBatch(ids);
        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<SysDictEntity> list = dictService.queryList(params);
        return R.ok().put("list", list);
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryDict")
    public R queryDict(@RequestBody SysDictEntity dict) {
        List<SysDictEntity> list = dictService.queryDict(dict);
        return R.ok().put("list", list);
    }

    /**
     * 查看
     */
    @RequestMapping("/getDictValue")
    public R getDictValue(@RequestParam Map<String, String> params) {
//        String groupCode = params.get("groupCode");
//        String dictKey = params.get("dictKey");
        String dictValue = "";
        return R.ok().put("dictValue", dictValue);
    }

    @RequestMapping("/area")
    public R queryAreaByPId(@RequestParam Map<String, Object> params) {
        List<Map<String, Object>> list = dictService.queryAreaByPId(params);
        return R.ok().put("list", list);
    }

    @RequestMapping("/queryByCompany")
    public R queryByCompany(@RequestParam Map<String, Object> params) {
        List<SysDictEntity> list = dictService.queryByCompany(params);
        return R.ok().put("list", list);
    }
}
